
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
      <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
	<!-- Bootstrap Styles-->
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
     <!-- FontAwesome Styles-->
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
        <!-- Custom Styles-->
    <link href="assets/css/custom-styles.css" rel="stylesheet" />
     <!-- Google Fonts-->
   <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
</head>
<body>
    <div id="wrapper">
        <nav class="navbar navbar-default top-navbar" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" ><i class="fa fa-gear"></i> <strong>学生成绩管理系统</strong></a>
            </div>

            <ul class="nav navbar-top-links navbar-right">
   
                <!-- /.dropdown -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                        <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li><a onclick= logout()><i class="fa fa-sign-out fa-fw"></i> 退出登录</a>
                        </li>
                    </ul>
                    <!-- /.dropdown-user -->
                </li>
                <!-- /.dropdown -->
            </ul>
        </nav>
        <!--/. NAV TOP  -->
        <nav class="navbar-default navbar-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav" id="main-menu">

                    <li>
                        <a  style="cursor:pointer" id = "a"><i class="fa fa-desktop"></i> 个人信息</a>
                    </li>

                    
                    <li>
                        <a  style="cursor:pointer" id = "b"><i class="fa fa-table"></i> 课程管理</a>
                    </li>
                    
                    <li>
                        <a  class="active-menu"><i class="fa fa-edit"></i> 修改密码</a>
                    </li>


      
                </ul>

            </div>

        </nav>
        <!-- /. NAV SIDE  -->
        <div id="page-wrapper" >
            <div id="page-inner">
			 <div class="row">
                    <div class="col-md-12">
                        <h1 class="page-header">
                            	修改密码 
                        </h1>
                    </div>
                </div> 
                 <!-- /. ROW  -->
              <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-6">
                                    <form role="form">
                                        <div class="form-group">
                                            <label>请输入原密码</label>
                                            <input class="form-control" type="password" id="oldpassword" placeholder="请输入原密码">
                                            
                                        </div>
                                        <div class="form-group">
                                            <label>请输入新密码</label>
                                            <input class="form-control" type="password" id="newpassword" placeholder="请输入新密码">
                                        </div>
                                        <div class="form-group">
                                            <label>请确认新密码</label>
                                            <input class="form-control" type="password" id="certainpassword" placeholder="请确认新密码">
                                        </div>
                           
                                        <button type="button" class="btn btn-success btn-lg" id = "modify">确认修改</button>
                                      <!--   <button type="reset" class="btn btn-default">Reset Button</button> -->
                                    </form>
                                </div>
      
                                <!-- /.col-lg-6 (nested) -->
                            </div>
                            <!-- /.row (nested) -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->

             <!-- /. PAGE INNER  -->
            </div>
         <!-- /. PAGE WRAPPER  -->
        </div>
     <!-- /. WRAPPER  -->
    <!-- JS Scripts-->
    <!-- jQuery Js -->
    <script src="assets/js/jquery-1.10.2.js"></script>
      <!-- Bootstrap Js -->
    <script src="assets/js/bootstrap.min.js"></script>
    <!-- Metis Menu Js -->
    <script src="assets/js/jquery.metisMenu.js"></script>
      <!-- Custom Js -->
    <script src="assets/js/custom-scripts.js"></script>
    
    <script type="text/javascript"> 
	    
        document.getElementById("a").onclick = function () {
        	window.location.href = "Teacher_Info.html";
        }

        document.getElementById("b").onclick = function () {
        	window.location.href = "Teacher_Courses.html";
        }
        function logout()
        {
            if (confirm("您确定退出吗？")) {  
                window.location.href = "Login.html";
            }             
        }
        
	    var name=localStorage.getItem("name");
            
	    document.getElementById("modify").onclick = function () {
	    	var oldpassword = document.getElementById("oldpassword").value;
	    	var newpassword = document.getElementById("newpassword").value;
	    	var certainpassword = document.getElementById("certainpassword").value;
	    	if(oldpassword == "") {
	    		alert("请输入原密码");
	    		return;
	    	}
	    	if(newpassword == "") {
			    alert("请输入新密码");
			    return;
			}
	    	if(certainpassword == "") {
			    alert("请确认新密码");
			    return;
			}
	    	if(newpassword != certainpassword) {
    		    alert("确认密码与新密码不相等，请重新输入");
    		    return;
    		}
            var url = "/teacher/change_password?teacher_id="+name+"&old_password="+password+"&new_password="+newpassword;
	        var ajaxObj = new XMLHttpRequest();	
	        ajaxObj.open('post', url);	
	        ajaxObj.send();	
	        ajaxObj.onreadystatechange = function () {
	            if (ajaxObj.readyState == 4 && ajaxObj.status == 200) {
	                console.log('数据返回成功');
	                console.log(ajaxObj.responseText);
	                alert("密码修改成功");
	            }
                else if(ajaxObj.readyState == 4 && ajaxObj.status == 404) {
                    var last=ajaxObj.responseText; //将JSON对象转化为JSON字符
                    var obj = JSON.parse(last);
                    alert(obj.error);
                }
	        };
	    }
    </script>
    
   
</body>
</html>
